#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<set>
using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
};


class Solution {
public:
    string tree2str(TreeNode* root) {
        string s;

        if (root == nullptr)
            return s;

        s += to_string(root->val);
        if (root->left || root->right)
        {
            s += '(';
            s += tree2str(root->left);
            s += ')';
        }

        if (root->right)
        {
            s += '(';
            s += tree2str(root->right);
            s += ')';
        }

        return s;
    }
};

int main()
{
    return 0;
}